﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using kk.components.contracts;

namespace ebc.patterns
{
    public static class Logger
    {
        public static Action<Request<TRequest, TResponse>> LogRequest<TRequest, TResponse>(Action<Request<TRequest, TResponse>> eventHandler)
        {
            return req =>
            {
                Console.WriteLine("Request: {0}", req.RequestData);
                var interceptedRequest = new Request<TRequest, TResponse>(
                    req.RequestData,
                    response =>
                    {
                        Console.WriteLine("Response: {0}", response);
                        req.ResponsePin(response);
                    });
                eventHandler(interceptedRequest);
            };
        }
    }
}
